package com.gyms.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gyms.R;
import com.classic.okhttp.beans.HVVenueItemBean;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import constant.EventConstant;
import utils.DateUtil;
import weight.UiEvent;

/**
 * ltx on 2016/11/11 09:26
 * 下订单适配器
 */
public class SeatOrderAdapter extends RecyclerView.Adapter<SeatOrderAdapter.ViewHolder> implements View.OnClickListener {
    private LayoutInflater mInflater;
    private List<HVVenueItemBean> mHVVenueItemBeanList;

    public SeatOrderAdapter(Context context)
    {
        mInflater = LayoutInflater.from(context);
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.seat_order_item,
                parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.mIvCancle= (ImageView) view.findViewById(R.id.iv_close);
        viewHolder.mSeatName= (TextView) view.findViewById(R.id.tv_seat_name);
        viewHolder.mSeatTime= (TextView) view.findViewById(R.id.tv_seat_time);
        viewHolder.mSeatDate= (TextView) view.findViewById(R.id.tv_seat_date);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        HVVenueItemBean mHVVenueItemBean=mHVVenueItemBeanList.get(position);
        holder.mSeatName.setText(mHVVenueItemBean.getVenueFieldName());
        int sTime=mHVVenueItemBean.getItemStartTime();//开始时间秒
        int eTime=mHVVenueItemBean.getItemEndTime();//结束时间秒
        String startTime=DateUtil.getHourAndMin(sTime);//拼接后的开始时间 小时跟秒
        String endTime=DateUtil.getHourAndMin(eTime);//拼接后的结束时间 小时跟秒
        holder.mSeatTime.setText(startTime+"-"+endTime);
        holder.mSeatDate.setText(DateUtil.getWeek(mHVVenueItemBean.getItemStartTime())+"（"+DateUtil.stampToDate(mHVVenueItemBean.getItemStartTime())+"）");

        holder.mIvCancle.setTag(position);
        holder.mIvCancle.setOnClickListener(this);

    }

    @Override
    public int getItemCount() {
        return mHVVenueItemBeanList==null?0:mHVVenueItemBeanList.size();
    }

    public void setHVVenueItemBeanList(List<HVVenueItemBean> HVVenueItemBeanList) {
        mHVVenueItemBeanList = HVVenueItemBeanList;
    }

    @Override
    public void onClick(View v) {
        int pos= (int) v.getTag();
        switch (v.getId()){
            case R.id.iv_close:
                EventBus.getDefault().post(new UiEvent(EventConstant.S_CANCEL_SEAT,pos));
                break;
        }

    }

    public class ViewHolder extends RecyclerView.ViewHolder
    {
        public ViewHolder(View arg0)
        {
            super(arg0);
        }

        TextView mSeatName;
        TextView mSeatTime;
        TextView mSeatDate;
        ImageView mIvCancle;

    }

}
